<?php
class Page extends MY_Model {
    var $table_name = 'page';
    var $primary_key = 'id';
	
    protected function filterData(&$data){
        if (isset($data['home'])){
            if (trim($data['home']) == '') unset ($data['home']);
        }
        if (isset($data['error'])){
            if (trim($data['error']) == '') unset ($data['error']);
        }
        foreach($data as $key=>$value){
            if (!$this->db->field_exists($key, $this->table_name)){
                unset($data[$key]);
            }else{
                $this->specialchars($data[$key]);
                if($key == 'elements'){
                    $data[$key] = serialize($data[$key]);
                }
            }
        }
        
    }
   
    private function specialchars(&$element){
        if (is_array($element)){
            foreach ($element as $key=>$item){
                $this->specialchars($element[$key]);
            }            
        }else{
            if ( get_magic_quotes_gpc() )
                $element = htmlspecialchars( stripslashes( $element ) ,ENT_QUOTES,'UTF-8') ;
            else
                $element = htmlspecialchars( $element ,ENT_QUOTES,'UTF-8') ;
        }
    }
}